package com.peakmain.wanandroid.mymodule;

import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.blankj.utilcode.util.SPUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.peakmain.minemodule.R;
import com.peakmain.minemodule.R2;
import com.peakmain.wanandroid.mymodule.activity.GankActivity;
import com.peakmain.wanandroid.mymodule.activity.PublicAccountActivity;
import com.peakmain.wanandroid.mymodule.base.BaseMineFragment;
import com.peakmain.wanandroid.mymodule.contract.LogoutContract;
import com.peakmain.wanandroid.mymodule.presenter.LogoutPresenter;

import butterknife.BindView;
import butterknife.OnClick;
import jp.wasabeef.glide.transformations.BlurTransformation;
import jp.wasabeef.glide.transformations.CropCircleTransformation;

/**
 * author: peakmain
 * createdata：2019/7/19
 * mail: 2726449200@qq.com
 * desiption:
 */
public class MineFragment extends BaseMineFragment<LogoutPresenter> implements LogoutContract.View {
    @BindView(R2.id.image_view)
    ImageView mImageView;
    @BindView(R2.id.iv_portrait)
    ImageView mIvPortrait;
    @BindView(R2.id.tv_name)
    TextView mTvName;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_mine;
    }

    @Override
    protected void initInjector() {
        mFragmentComponent.inject(this);
    }

    @Override
    protected void initView(View view) {
        Glide.with(this)
                .load(R.drawable.port)
                .into(mImageView);
        Glide.with(this).load(R.drawable.port)
                .into(mIvPortrait);
        String account = SPUtils.getInstance().getString("account");
        mTvName.setText(!TextUtils.isEmpty(account)?account:"Peakmain");
    }

    @OnClick(R2.id.bt_logout)
    public void onClick(View view) {
        if (view.getId() == R.id.bt_logout) {
            new AlertDialog.Builder(getContext())
                    .setTitle("退出登录")
                    .setMessage("您确定退出登录吗?")
                    .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            mPresenter.logout();
                        }
                    })
                    .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    }).show();

        }
    }

    @Override
    public void showLogoutSuccess() {
        SPUtils.getInstance().put("account", "");
        SPUtils.getInstance().put("password", "");
        ToastUtils.showShort("退出登录成功");
        ARouter.getInstance().build("/activity/loginActivity").navigation();
        getActivity().finish();
    }

    @OnClick({R2.id.iv_wx_public,R2.id.iv_mine_meizi})
    public void click(View view){
        if(view.getId()==R.id.iv_wx_public){
           startActivity(new Intent(getContext(), PublicAccountActivity.class));
        }
        if(view.getId()==R.id.iv_mine_meizi){
            startActivity(new Intent(getContext(), GankActivity.class));
        }
    }
}
